<?php
require_once("../admin/action/sys_conf.inc");
	$link_id = mysql_connect($DBHOST,$DBUSER,$DBPWD);
	mysql_select_db($DBNAME);
	mysql_query("SET NAMES 'utf8'");
	$uid = 1;//根据其他程序找到uid
	$pageSize=8;
	$page = $_REQUEST['page'] ? $_REQUEST['page'] : 1;
	$sid = $_REQUEST[id];
	$sql ="SELECT * FROM extpollitems where subjectId = '$sid'";
	$result = mysql_query($sql);
	$query = "select subject from extpollsubject where id ='$sid'";
	$rs = mysql_query($query);
	$subject = mysql_fetch_assoc($rs);
?>

<table width="750" height="380" border="0" cellpadding="5" cellspacing="5" align="center">
  <caption>
    <?= $subject[subject] ?>
  </caption>
 
  	<?php 
	if(!$numRows = mysql_num_rows($result)){
		echo "Sorry,目前没有数据";
		exit;
	}
	else{
		$MaxPage=(int)ceil($numRows/$pageSize);
		
		if((int)$page > $MaxPage)
			$page=$MaxPage;
		if(mysql_data_seek($result,($page-1)*$pageSize))
		{
			while($option = mysql_fetch_array($result)){
				$i = $option[0];
				$oid = $option[id];
				$name = $option[name];
				$introduction = $option[introduction];
				$amount = $option[amount];
				$sql2 = "select * from extpollmedia where subjectItemId = '$oid' and mediaType = 0 and listVisible = 1";
				$result2 = mysql_query($sql2);
				$media = mysql_fetch_assoc($result2);
				$path = "/poll".$media[path];
				$title = $media[title];
?>
<?php 
	if($i%4==1)
		echo '<tr>';
?>
    <td><table width="150" border="0" cellspacing="0" cellpadding="5" align="center">
      <tr>
        <td><img src="<?= $path ?>" alt="<?= $title ?>" title="<?= $title ?>" width="130" height="100"/></td>
      </tr>
      <tr>
        <td>
					<table width="100%" border="0" cellspacing="5" cellpadding="0">
						<tr>
							<td><?= $name ?></td>
							<td id="pn_<?=$oid ?>"><?= $amount ?>票</td>
						</tr>
					</table>
				</td>
      </tr>
      <tr>     	
        <td align="center">
						<button onclick="javascript:vote(<?=$oid ?>)">投票</button>
				</td>			
      </tr>
    </table></td>
    <?php 
	if($i%4==0)
		echo '</tr>';
?>
  <?php if(($i-($page-1)*$pageSize) == $pageSize) break;}}} ?>
</table>

 <table width="750" border="0" cellpadding="0" cellspacing="0" align="center">
<tr align="center"><td width="100%"><?php
if($MaxPage>1){
	echo '<div class="quotes">';
	if($page==1)
			echo '<span class="disabled">上一页 </span>';
		else
			echo '<a href="javascript:void(0);" onclick="flip('.($page-1).')">上一页</a>';
	for($i=1;$i<=$MaxPage;$i++){
		if($i==$page)
			echo '<span class="current">'.$i.'</span>';
		else
			echo '<a href="javascript:void(0);" onclick="flip('.$i.')">'.$i.'</a>';		
	}
	if($page==$MaxPage)
			echo '<span class="disabled">下一页 </span>';
		else
			echo '<a href="javascript:void(0);"  onclick="flip('.($page+1).')">下一页</a>';
	echo '</div>';
}
?></td></tr>
</table>
